package com.blockchain.securewallet.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.blockchain.securewallet.R;
import com.blockchain.securewallet.base.BaseActivity;
import com.blockchain.securewallet.dialog.BottomSlide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WalletInitActivity extends BaseActivity {

    public static final String KEY_MODULE_FROM = "key_module_from";

    private int from;

    private static final String TAG = "Wallet.Init";

    @BindView(R.id.btn_wallet_create)
    Button mBtnCreate;

    @BindView(R.id.btn_wallet_restore)
    Button mBtnRestore;

    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.init_title)
    View title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet_init);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        if (intent != null) {
            from = intent.getIntExtra(KEY_MODULE_FROM, 0);
        }

        tvTitle.setText(R.string.app_name);

        if (from == 0) {
            title.setVisibility(View.GONE);
        }

    }

    @OnClick(R.id.btn_wallet_create)
    void createWallet() {
        Intent intent = new Intent();
        intent.setClass(this, WalletCreateActivity.class);
        startActivity(intent);
    }


    @OnClick(R.id.btn_wallet_restore)
    void restoreWallet() {
        BottomSlide dialog = BottomSlide.newInstance("", new String[]{getString(R.string.recover_password), getString(R.string.recover_scan_qrcode)});
        dialog.show(getSupportFragmentManager(), "dialog");
        //add item click listener
        dialog.setListener(new BottomSlide.OnClickListener() {
            @Override
            public void click(int position) {
                if (position == 0) {
                    Intent intent = new Intent();
                    intent.setClass(WalletInitActivity.this, SeedWordsInputActivity.class);
                    WalletInitActivity.this.startActivity(intent);
                } else {
                    Intent intent = new Intent();
                    intent.setClass(WalletInitActivity.this, QrCodeScanActivity.class);
                    intent.putExtra(QrCodeScanActivity.KEY_MODULE_FROM, QrCodeScanActivity.MODULE_RESTORE_SEED);
                    WalletInitActivity.this.startActivity(intent);
                }
            }
        });
    }

    @OnClick(R.id.btn_back)
    void back() {
//        finish();
        if (from == 0)
            return;
        super.onBackPressed();
    }

    @Override
    public void onBackPressed() {
        if (from == 0)
            return;
        super.onBackPressed();
    }

}
